home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer: Getting Started / Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin / pc / mac / bonus / peter_le / dehqx-20 / myapplee.uni < prev    next >
Text File  |  1991-08-23  |  4KB  |  129 lines

  1. unit MyAppleEvents;
  2. { DeHQX v2.0.0 ⌐ Peter Lewis, Aug 1991 }
  3.  
  4. interface
  5.  
  6. {    uses}
  7. {    MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, Traps, Files, Aliases, AppleEvents, GestaltEqu, MacPrint;}
  8.     uses
  9.         Types, OSUtils, Files, AppleTalk, PPCToolbox, Processes, EPPC, Notification, AppleEvents, MyUtilities;
  10.  
  11.     function InitAppleEvents (DoOApp, DoODoc, DoPrint, DoQuit: Ptr): OSErr;
  12. { function DoOApp: OSErr }
  13. { function DoODoc (fs: FSSpec): OSErr }
  14. { function DoPrint (fs: FSSpec): OSErr }
  15. { function DoQuit: OSErr}
  16.  
  17. implementation
  18.  
  19.     function DoOApp (p: ptr): OSErr;
  20.     inline
  21.         $205F, $4E90;
  22.  
  23.     function DoDocs (fs: FSSpec; p: ptr): OSErr;
  24.     inline
  25.         $205F, $4E90;
  26.  
  27.     function DoQuit (p: ptr): OSErr;
  28.     inline
  29.         $205F, $4E90;
  30.  
  31.     const
  32.         kPatienceLevel = 1000;                                { <aevt> ticks we wait for response }
  33.         kSysEnvironsVersion = 1;
  34.         kOSEvent = app4Evt;    {event used by MultiFinder}
  35.         kSuspendResumeMessage = 1;        {high byte of suspend/resume event message}
  36.         kResumeMask = 1;        {bit of message field for resume vs. suspend}
  37.         kMouseMovedMessage = $FA;        {high byte of mouse-moved event message}
  38.         kNoEvents = 0;        {no events mask}
  39.         kNoListChosen = -1;
  40.  
  41.     function GotRequiredParams (theAppleEvent: AppleEvent): OSErr;        { <aevt> }
  42.         var
  43.             typeCode: DescType;
  44.             actualSize: Size;
  45.             err: OSErr;
  46.     begin
  47.         err := AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard, typeCode, nil, 0, actualSize);    { nil ok: need only function result }
  48.         if err = errAEDescNotFound then        { we got all the required params: all is ok }
  49.             GotRequiredParams := noErr
  50.         else if err = noErr then
  51.             GotRequiredParams := errAEEventNotHandled
  52.         else
  53.             GotRequiredParams := err;
  54.     end; { GotRequiredParams }
  55.  
  56.     function HandleOAPP (theAppleEvent, reply: AppleEvent; openappp: ptr): OSErr;{ <aevt> }
  57.         var
  58.             oe: OSErr;
  59.     begin
  60.     { We don't expect any params at all, but check in case the client requires any }
  61.         oe := GotRequiredParams(theAppleEvent);
  62.         oe := DoOApp(openappp);
  63.         HandleOAPP := oe;
  64.     end;
  65.  
  66.     function HandleDocs (theAppleEvent, reply: AppleEvent; dodocp: ptr): OSErr;        { <aevt> }
  67.         var
  68.             myFSS: FSSpec;
  69.             docList: AEDescList;
  70.             index, itemsInList: LONGINT;
  71.             actualSize: Size;
  72.             keywd: AEKeyword;
  73.             typeCode: descType;
  74.             ignoreWPtr: WindowPtr;
  75.             oe, ooe: OSErr;
  76.     begin
  77.         oe := AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, docList);
  78.         if oe = noErr then begin
  79.             ooe := GotRequiredParams(theAppleEvent);
  80.     { now get each alias from the list (as an FSSSpec) and open the associated file. }
  81.             oe := AECountItems(docList, itemsInList);
  82.             for index := 1 to itemsInList do begin
  83.                 ooe := AEGetNthPtr(docList, index, typeFSS, keywd, typeCode, @myFSS, sizeof(myFSS), actualSize);
  84. { coercion does alias->fsspec }
  85.                 if ooe = noErr then
  86.                     ooe := DoDocs(myFSS, dodocp);
  87.             end;
  88.             ooe := AEDisposeDesc(docList);
  89.         end;
  90.         HandleDocs := oe;
  91.     end; { HandleDocs }
  92.  
  93.     function HandleQUIT (theAppleEvent, reply: AppleEvent; quitp: ptr): OSErr;        { <aevt> }
  94.         var
  95.             oe: OSErr;
  96.             errStr: Str255;
  97.             willQuit: Boolean;                { did the user allow the quit or cancel }
  98.     begin
  99.     { We don't expect any params at all, but check in case the client requires any }
  100.         oe := GotRequiredParams(theAppleEvent);
  101.         oe := DoQuit(quitp);            { set global boolean: app will exit at end of event loop }
  102.         if reply.dataHandle <> nil then            { a reply is sought }
  103.             begin
  104.             if oe = noErr then
  105.                 errStr := 'OK'
  106.             else
  107.                 errStr := 'user cancelled quit';
  108.             oe := AEPutParamPtr(reply, 'errs', 'TEXT', Ptr(@errStr[1]), length(errStr));
  109.         end;
  110.         HandleQUIT := oe;
  111.     end;
  112.  
  113.     function InitAppleEvents (DoOApp, DoODoc, DoPrint, DoQuit: Ptr): OSErr;
  114.         var
  115.             aevtErr: OSErr;
  116.     begin
  117.         aevtErr := noErr;
  118.         if (aevtErr = noErr) and (DoOApp <> nil) then
  119.             aevtErr := AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, @HandleOAPP, longInt(DoOApp), false);
  120.         if (aevtErr = noErr) and (DoODoc <> nil) then
  121.             aevtErr := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, @HandleDocs, longInt(DoODoc), false);
  122.         if (aevtErr = noErr) and (DoPrint <> nil) then
  123.             aevtErr := AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, @HandleDocs, longInt(DoPrint), false);
  124.         if (aevtErr = noErr) and (DoQuit <> nil) then
  125.             aevtErr := AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, @HandleQUIT, longInt(DoQuit), false);
  126.         InitAppleEvents := aevtErr;
  127.     end;
  128.  
  129. end.